// GenICamVc6TestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GenICamVc6Test.h"
#include "GenICamVc6TestDlg.h"

#include "GenICam/System.h"
#include <stdio.h>

using namespace Dahua;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGenICamVc6TestDlg dialog

CGenICamVc6TestDlg::CGenICamVc6TestDlg(CWnd* pParent )
	: CDialog(CGenICamVc6TestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGenICamVc6TestDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGenICamVc6TestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGenICamVc6TestDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGenICamVc6TestDlg, CDialog)
	//{{AFX_MSG_MAP(CGenICamVc6TestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_CONNECT, OnButtonConnect)
	ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, OnButtonDisconnect)
	ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
	ON_BN_CLICKED(IDC_BUTTON_STOPPLAY, OnButtonStopplay)
	ON_BN_CLICKED(IDC_BUTTON_DISCOVERY, OnButtonDiscovery)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
    ON_CBN_KILLFOCUS(IDC_COMBO_EXPOSUREAUTO, OnCbnKillfocusComboExposureauto)
    ON_CBN_KILLFOCUS(IDC_COMBO_EXPOSUREMODE, OnCbnKillfocusComboExposuremode)
    ON_EN_KILLFOCUS(IDC_EDIT_EXPOSURETIME, OnEnKillfocusEditExposuretime)
    ON_EN_KILLFOCUS(IDC_EDIT_GAINRAW, OnEnKillfocusEditGainraw)
    ON_EN_KILLFOCUS(IDC_EDIT_FRAMERATE, OnEnKillfocusEditFramerate)
    ON_CBN_KILLFOCUS(IDC_COMBO_PIXELFORMAT, OnCbnKillfocusComboPixelformat)
    ON_CBN_KILLFOCUS(IDC_COMBO_GAINAUTO, OnCbnKillfocusComboGainauto)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGenICamVc6TestDlg message handlers

BOOL CGenICamVc6TestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_PLAY)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_STOPPLAY)->EnableWindow(FALSE);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGenICamVc6TestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGenICamVc6TestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGenICamVc6TestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGenICamVc6TestDlg::OnButtonConnect() 
{
	// TODO: Add your control notification handler code here
	if ( !m_sptrMvCamera )
	{
		AfxMessageBox(_T("No camera!"));
		return;
	}
	
	bool bOpenRet = m_sptrMvCamera->open(NULL);
	if ( !bOpenRet )
	{
		AfxMessageBox(_T("Connect failed!"));
		return;
	}
	
	GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_PLAY)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_STOPPLAY)->EnableWindow(FALSE);
    GetDlgItem(IDC_BUTTON_DISCOVERY)->EnableWindow(FALSE);
	
	AfxMessageBox(_T("Connect success!"));

	initParamProperties();
}

void CGenICamVc6TestDlg::OnButtonDisconnect() 
{
	// TODO: Add your control notification handler code here
	if ( m_sptrMvCamera )
	{
		m_sptrMvCamera->stopDisplay();
		m_sptrMvCamera->close();
	}

	GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_PLAY)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_STOPPLAY)->EnableWindow(FALSE);
    GetDlgItem(IDC_BUTTON_DISCOVERY)->EnableWindow(TRUE);
}

void CGenICamVc6TestDlg::OnButtonPlay() 
{
	// TODO: Add your control notification handler code here
	if ( m_sptrMvCamera )
	{
		m_sptrMvCamera->startDisplay((VR_HWND)GetDlgItem(IDC_LIST_SHOWWINDOW)->GetSafeHwnd());

		GetDlgItem(IDC_BUTTON_PLAY)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON_STOPPLAY)->EnableWindow(TRUE);
	}
	else
	{
		AfxMessageBox(_T("Start play failed!"));
		return;
	}	
}

void CGenICamVc6TestDlg::OnButtonStopplay() 
{
	// TODO: Add your control notification handler code here
	if ( m_sptrMvCamera )
	{
		m_sptrMvCamera->stopDisplay();
	}
	
	GetDlgItem(IDC_BUTTON_PLAY)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_STOPPLAY)->EnableWindow(FALSE);
}

void CGenICamVc6TestDlg::OnButtonDiscovery() 
{
	// TODO: Add your control notification handler code here
	Infra::TVector<GenICam::ICameraPtr> vecCameras;

	GenICam::CSystem::getInstance().discovery(vecCameras);

	int iNum = vecCameras.size();
	if ( iNum > 0 )
	{
		m_sptrMvCamera = CMvCameraPtr(new CMvCamera(vecCameras[0]));

		GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(TRUE);

		AfxMessageBox(_T("Discovery success!"));
	}
	else
	{
		AfxMessageBox(_T("Discovery can't find cameras!"));
	}
}

void CGenICamVc6TestDlg::initParamProperties()
{
	CMvCamera::ParamControlSetPtr sptrParamCtrlSet = m_sptrMvCamera->getParamControl();
	if ( !sptrParamCtrlSet )
	{
		AfxMessageBox(_T("Read camera parameters failed!"));
	}

	// exposureAuto
	GenICam::CEnumNode sptrExposureAuto = sptrParamCtrlSet->_sptrAcquistionCtrl->exposureAuto();
	CWnd* pCmbExposureAuto = GetDlgItem(IDC_COMBO_EXPOSUREAUTO);
	initComboBoxTypeProperty(sptrExposureAuto, pCmbExposureAuto);
    GetDlgItemText(IDC_COMBO_EXPOSUREAUTO, m_paramStruct.preExposureautoStr);

	// exposureMode
	GenICam::CEnumNode sptrExposureMode = sptrParamCtrlSet->_sptrAcquistionCtrl->exposureMode();
	CWnd* pCmbExposureMode = GetDlgItem(IDC_COMBO_EXPOSUREMODE);
	initComboBoxTypeProperty(sptrExposureMode, pCmbExposureMode);
    GetDlgItemText(IDC_COMBO_EXPOSUREMODE, m_paramStruct.preExposuremodeStr);

	// exposureTime
	GenICam::CDoubleNode sptrExposureTime = sptrParamCtrlSet->_sptrAcquistionCtrl->exposureTime();
	CWnd* pEditExposureTime = GetDlgItem(IDC_EDIT_EXPOSURETIME);
	initFloatEditTypeProperty(sptrExposureTime, pEditExposureTime);
    GetDlgItemText(IDC_EDIT_EXPOSURETIME, m_paramStruct.preExposuretimeStr);

	// gainAuto
	GenICam::CEnumNode sptrGainAuto = sptrParamCtrlSet->_sptrAnalogCtrl->gainAuto();
	CWnd* pCmbGainAuto = GetDlgItem(IDC_COMBO_GAINAUTO);
	initComboBoxTypeProperty(sptrGainAuto, pCmbGainAuto);
    GetDlgItemText(IDC_COMBO_GAINAUTO, m_paramStruct.preGainautoStr);

	// gainRaw
	GenICam::CDoubleNode sptrGainRaw = sptrParamCtrlSet->_sptrAnalogCtrl->gainRaw();
	CWnd* pEditGainRaw = GetDlgItem(IDC_EDIT_GAINRAW);
	initFloatEditTypeProperty(sptrGainRaw, pEditGainRaw);
    GetDlgItemText(IDC_EDIT_GAINRAW, m_paramStruct.preGainrawStr);

	// acquistionFrameRate
	GenICam::CDoubleNode sptrFrameRate = sptrParamCtrlSet->_sptrAcquistionCtrl->acquisitionFrameRate();
	CWnd* pEditFrameRate = GetDlgItem(IDC_EDIT_FRAMERATE);
	initFloatEditTypeProperty(sptrFrameRate, pEditFrameRate);
    GetDlgItemText(IDC_EDIT_FRAMERATE, m_paramStruct.preFramerateStr);

	// pixelFormat
	GenICam::CEnumNode sptrPixelFormat = sptrParamCtrlSet->_sptrImageFormatCtrl->pixelFormat();
	CWnd* pCmbPixelFormat = GetDlgItem(IDC_COMBO_PIXELFORMAT);
	initComboBoxTypeProperty(sptrPixelFormat, pCmbPixelFormat);
    GetDlgItemText(IDC_COMBO_PIXELFORMAT, m_paramStruct.prePixelformatStr);
}

void CGenICamVc6TestDlg::initComboBoxTypeProperty(GenICam::CEnumNode sptrEnumNode, CWnd* pCmbProperty)
{
	if ( !sptrEnumNode.isValid() ||	NULL == pCmbProperty )
	{
		return;
	}

	CComboBox* pComboBox = (CComboBox*)pCmbProperty;

    pComboBox->ResetContent();

	Infra::CString valEnumSymbol;
	sptrEnumNode.getValueSymbol(valEnumSymbol);
	Infra::TVector<Infra::CString> vecEnumEntrys = sptrEnumNode.getEnumSymbolList();
	for (uint32_t iIndex = 0; iIndex < vecEnumEntrys.size(); ++iIndex)
	{
		pComboBox->InsertString(iIndex,(LPCTSTR)vecEnumEntrys[iIndex].c_str());
		if ( valEnumSymbol == vecEnumEntrys[iIndex] )
		{
			pComboBox->SetCurSel(iIndex);
		}
	}

	BOOL bEnable = sptrEnumNode.isWriteable() ? TRUE : FALSE;
	pComboBox->EnableWindow(bEnable);
}

void CGenICamVc6TestDlg::initFloatEditTypeProperty(Dahua::GenICam::CDoubleNode sptrDoubleNode, CWnd* pEditProperty)
{
	if ( !sptrDoubleNode.isValid() || !pEditProperty )
	{
		return;
	}

	double fltVal = 0.0;
	sptrDoubleNode.getValue(fltVal);

	char szBuf[24] = {0};
	sprintf( szBuf, "%5f", fltVal );

	pEditProperty->SetWindowText((LPCTSTR)szBuf);

	BOOL bEnable = sptrDoubleNode.isWriteable() ? TRUE : FALSE;
	pEditProperty->EnableWindow(bEnable);
}

void CGenICamVc6TestDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	OnButtonStopplay();
	
	CDialog::OnClose();
}

void CGenICamVc6TestDlg::OnOK()
{
    // do nothing 防止按下回车键后， 程序退出
	// do nothing prevent the program from exiting after pressing enter
    GetDlgItem(IDC_BUTTON_DISCOVERY)->SetFocus();
}

void CGenICamVc6TestDlg::OnCbnKillfocusComboExposureauto()
{
    // TODO: 在此添加控件通知处理程序代码
	// TODO: Add control notification handler code here
    if (m_sptrMvCamera && m_sptrMvCamera->isOpen())
    {
        CMvCamera::ParamControlSetPtr sptrParamCtrlSet = m_sptrMvCamera->getParamControl();

        CString curStr;
        GetDlgItemText(IDC_COMBO_EXPOSUREAUTO, curStr);
        if (m_paramStruct.preExposureautoStr == curStr)
        {
            return;
        }

        Infra::CString infraStr(curStr);
        if (!sptrParamCtrlSet->_sptrAcquistionCtrl->exposureAuto().setValueBySymbol(infraStr))
        {
            AfxMessageBox(_T("set exposureAuto failed!"));
            if (m_paramStruct.preExposureautoStr != "")
            {
                SetDlgItemText(IDC_COMBO_EXPOSUREAUTO, m_paramStruct.preExposureautoStr);
            }
            else
            {
                m_paramStruct.preExposureautoStr = curStr;
            }
        }
        else
        {
            m_paramStruct.preExposureautoStr = curStr;
        }
    }
}

void CGenICamVc6TestDlg::OnCbnKillfocusComboExposuremode()
{
    // TODO: 在此添加控件通知处理程序代码
	// TODO: Add control notification handler code here
    if (m_sptrMvCamera && m_sptrMvCamera->isOpen())
    {
        CMvCamera::ParamControlSetPtr sptrParamCtrlSet = m_sptrMvCamera->getParamControl();

        CString curStr;
        GetDlgItemText(IDC_COMBO_EXPOSUREMODE, curStr);
        if (m_paramStruct.preExposuremodeStr == curStr)
        {
            return;
        }

        Infra::CString infraStr(curStr);
        if (!sptrParamCtrlSet->_sptrAcquistionCtrl->exposureMode().setValueBySymbol(infraStr))
        {
            AfxMessageBox(_T("set exposureMode failed!"));
            if (m_paramStruct.preExposuremodeStr != "")
            {
                SetDlgItemText(IDC_COMBO_EXPOSUREMODE, m_paramStruct.preExposuremodeStr);
            }
            else
            {
                m_paramStruct.preExposuremodeStr = curStr;
            }
        }
        else
        {
            m_paramStruct.preExposuremodeStr = curStr;
        }
    }
}

void CGenICamVc6TestDlg::OnEnKillfocusEditExposuretime()
{
    // TODO:  在此添加控件通知处理程序代码
	// TODO:  Add control notification handler code here
    if (m_sptrMvCamera && m_sptrMvCamera->isOpen())
    {
        CMvCamera::ParamControlSetPtr sptrParamCtrlSet = m_sptrMvCamera->getParamControl();

        CString curStr;
        GetDlgItemText(IDC_EDIT_EXPOSURETIME, curStr);
        if (m_paramStruct.preExposuretimeStr == curStr)
        {
            return;
        }

        double dVal = atof(curStr);
        if (!sptrParamCtrlSet->_sptrAcquistionCtrl->exposureTime().setValue(dVal))
        {
            AfxMessageBox(_T("set exposureTime failed!"));
            if (m_paramStruct.preExposuretimeStr != "")
            {
                SetDlgItemText(IDC_EDIT_EXPOSURETIME, m_paramStruct.preExposuretimeStr);
            }
            else
            {
                m_paramStruct.preExposuretimeStr = curStr;
            }
        }
        else
        {
            m_paramStruct.preExposuretimeStr = curStr;
        }
    }
}

void CGenICamVc6TestDlg::OnEnKillfocusEditGainraw()
{
    // TODO:  在此添加控件通知处理程序代码
	// TODO:  Add control notification handler code here
    if (m_sptrMvCamera && m_sptrMvCamera->isOpen())
    {
        CMvCamera::ParamControlSetPtr sptrParamCtrlSet = m_sptrMvCamera->getParamControl();

        CString curStr;
        GetDlgItemText(IDC_EDIT_GAINRAW, curStr);
        if (m_paramStruct.preGainrawStr == curStr)
        {
            return;
        }

        double dVal = atof(curStr);
        if (!sptrParamCtrlSet->_sptrAnalogCtrl->gainRaw().setValue(dVal))
        {
            AfxMessageBox(_T("set gainRaw failed!"));
            if (m_paramStruct.preGainrawStr != "")
            {
                SetDlgItemText(IDC_EDIT_GAINRAW, m_paramStruct.preGainrawStr);
            }
            else
            {
                m_paramStruct.preGainrawStr = curStr;
            }
        }
        else
        {
            m_paramStruct.preGainrawStr = curStr;
        }
    }
}

void CGenICamVc6TestDlg::OnEnKillfocusEditFramerate()
{
    // TODO: 在此添加控件通知处理程序代码
	// TODO: Add control notification handler code here
    if (m_sptrMvCamera && m_sptrMvCamera->isOpen())
    {
        CMvCamera::ParamControlSetPtr sptrParamCtrlSet = m_sptrMvCamera->getParamControl();

        CString curStr;
        GetDlgItemText(IDC_EDIT_FRAMERATE, curStr);
        if (m_paramStruct.preFramerateStr == curStr)
        {
            return;
        }

        if (!sptrParamCtrlSet->_sptrAcquistionCtrl->acquisitionFrameRateEnable().setValue(true))
        {
            AfxMessageBox(_T("set acquisitionFrameRateEnable failed!"));
        }

        double dVal = atof(curStr);
        if (!sptrParamCtrlSet->_sptrAcquistionCtrl->acquisitionFrameRate().setValue(dVal))
        {
            AfxMessageBox(_T("set acquisitionFrameRate failed!"));
            if (m_paramStruct.preFramerateStr != "")
            {
                SetDlgItemText(IDC_EDIT_FRAMERATE, m_paramStruct.preFramerateStr);
            }
            else
            {
                m_paramStruct.preFramerateStr = curStr;
            }
        }
        else
        {
            m_paramStruct.preFramerateStr = curStr;
        }
    }
}

void CGenICamVc6TestDlg::OnCbnKillfocusComboPixelformat()
{
    // TODO:  在此添加控件通知处理程序代码
	// TODO:  Add control notification handler code here
    if (m_sptrMvCamera && m_sptrMvCamera->isOpen())
    {
        CMvCamera::ParamControlSetPtr sptrParamCtrlSet = m_sptrMvCamera->getParamControl();

        CString curStr;
        GetDlgItemText(IDC_COMBO_PIXELFORMAT, curStr);
        if (m_paramStruct.prePixelformatStr == curStr)
        {
            return;
        }

        Infra::CString infraStr(curStr);
        if (!sptrParamCtrlSet->_sptrImageFormatCtrl->pixelFormat().setValueBySymbol(infraStr))
        {
            AfxMessageBox(_T("set pixelFormat failed!"));
            if (m_paramStruct.prePixelformatStr != "")
            {
                SetDlgItemText(IDC_COMBO_PIXELFORMAT, m_paramStruct.prePixelformatStr);
            }
            else
            {
                m_paramStruct.prePixelformatStr = curStr;
            }
        }
        else
        {
            m_paramStruct.prePixelformatStr = curStr;
        }
    }
}

void CGenICamVc6TestDlg::OnCbnKillfocusComboGainauto()
{
    // TODO:  在此添加控件通知处理程序代码
	// TODO:  Add control notification handler code here
    if (m_sptrMvCamera && m_sptrMvCamera->isOpen())
    {
        CMvCamera::ParamControlSetPtr sptrParamCtrlSet = m_sptrMvCamera->getParamControl();

        CString curStr;
        GetDlgItemText(IDC_COMBO_GAINAUTO, curStr);
        if (m_paramStruct.preGainautoStr == curStr)
        {
            return;
        }

        Infra::CString infraStr(curStr);
        if (!sptrParamCtrlSet->_sptrAnalogCtrl->gainAuto().setValueBySymbol(infraStr))
        {
            AfxMessageBox(_T("set gainAuto failed!"));
            if (m_paramStruct.preGainautoStr != "")
            {
                SetDlgItemText(IDC_COMBO_GAINAUTO, m_paramStruct.preGainautoStr);
            }
            else
            {
                m_paramStruct.preGainautoStr = curStr;
            }
        }
        else
        {
            m_paramStruct.preGainautoStr = curStr;
        }
    }
}
